home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / CONTRIB / ASPI.ZIP / taperead.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-25  |  1.2 KB  |  71 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <io.h>
  5. #include <fcntl.h>
  6. #include <sys/stat.h>
  7.  
  8. #include "aspi.h"
  9. #include "tape.h"
  10.  
  11. unsigned block_size = 20*512U;
  12. char *buffer;
  13.  
  14. int data_f;
  15.  
  16. void do_read(void)
  17. {
  18.   int stat, i, c;
  19.   unsigned long total = 0;
  20.  
  21.   tape_set_blocksize(block_size);
  22.  
  23.   while (1)
  24.   {
  25.     if (tape_read(buffer))
  26.       break;
  27.  
  28.     write(data_f, buffer, block_size);
  29.     total += block_size;
  30.     printf("  %s\r", tape_fmtnum(total));
  31.     fflush(stdout);
  32.   }
  33.   printf("\n", total);
  34. }
  35.  
  36.  
  37. int main(int argc, char **argv)
  38. {
  39.   int stat;
  40.   if (argc < 2)
  41.   {
  42.     printf("datread [-b blocks(512ea)] file\n");
  43.     printf("  ex: blocks = 20 is 10K\n");
  44.     return 1;
  45.   }
  46.  
  47.   if (strcmp(argv[1], "-b") == 0)
  48.   {
  49.     block_size = atoi(argv[2]) * 512UL;
  50.     argc -= 2;
  51.     argv += 2;
  52.   }
  53.   
  54.   data_f = open(argv[1], O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, 0666);
  55.   if (data_f < 0)
  56.   {
  57.     perror("Opening output data file");
  58.     exit(1);
  59.   }
  60.  
  61.   buffer = (char *)malloc(block_size);
  62.   aspi_buffer_length = block_size;
  63.   tape_open();
  64.   do_read();
  65.   tape_close();
  66.  
  67.   close(data_f);
  68.  
  69.   return 0;
  70. }
  71.